#ifndef PLINTH_H3D_H
#define PLINTH_H3D_H

#define HORDE3D_OBJ_ID 126451

#include "../core/AbstractObject.h"
#include "../core/ObjectFactory.h"
#include "../core/SimpleImage.h"

// Forward declare this in case we don't need CPP horde3d access
typedef int H3DNode;
typedef int H3DRes;

int returnThreePlusX(int x);

class Horde3d : public AbstractObject
{
public:
	Horde3d();

	// Return the c++ type id
	virtual int getCppTypeId();
	// Returns whether this can be cast to a given type
	virtual bool isType(int id);

	// Return the c++ type as a string 
	virtual std::string getCppTypeName();

	// returns a description of this thing
	virtual std::string getDescription();

	// create another one of these
	virtual AbstractObject* newInstance();

	// init & update
	virtual void init();
	virtual void update(double dt);

	// push its static functions into the given lua table
	virtual void pushStaticFuncs(lua_State* L);

	virtual ~Horde3d();
	
	void resetVideoMode(int desired_w, int desired_h, bool fullscreen);
	void initGraphicsMinimal(int desired_w, int desired_h, bool fullscreen);
	void initGraphics(int desired_w, int desired_h, bool fullscreen);
	void enableAutoUpdate(H3DNode updateCam);
	void disableAutoUpdate();
	static void setNodeTransformQuaternion(H3DNode n, float tx, float ty, float tz, float rx, float ry, float rz, float rw, float sx, float sy, float sz);
	SimpleImage* getScreenshot(SimpleImage* dest = NULL, bool backBuffer = false);
	SimpleImage* getTextureAsImage(H3DRes texRes, SimpleImage* dest = NULL);
	void setTextureFromImage(H3DRes texRes, SimpleImage* src);
	H3DRes getTextureResFromMaterial(H3DRes matRes, std::string& samplerName);
	void setTextureResForMaterial(H3DRes matRes, std::string& samplerName, H3DRes texRes);
	void setSwapBufferInterval(int bufferInterval);
	void forceBufferSwap();

	// some custom interface stuff
	static int li_loadResourcesFromDisk(lua_State* L);
	static int li_setNodeTransformQuaternion(lua_State* L);
	static int li_getOption(lua_State* L);
	static int li_setOption(lua_State* L);
	static int li_getStat(lua_State* L);
	static int li_resetVideoMode(lua_State* L);
	static int li_initGraphicsMinimal(lua_State* L);
	static int li_initGraphics(lua_State* L);
	static int li_enableAutoUpdate(lua_State* L);
	static int li_disableAutoUpdate(lua_State* L);
	static int li_getScreenshot(lua_State* L);
	static int li_getBBScreenshot(lua_State* L);
	static int li_createImage(lua_State* L);
	static int li_getTextureAsImage(lua_State* L);
	static int li_setTextureFromImage(lua_State* L);
	static int li_getTextureResFromMaterial(lua_State* L);
	static int li_setTextureResForMaterial(lua_State* L);
	static int li_asInt(lua_State* L);
	static int li_asRes(lua_State* L);
	static int li_asNode(lua_State* L);
	static int li_setSwapBufferInterval(lua_State* L);
	static int li_forceBufferSwap(lua_State* L);
	static int li_drawAAROIOverlay(lua_State* L);
	static int li_getNodeTransMats(lua_State* L);

private:
	bool _autoUpdating;
	H3DNode _autoCam;
	bool _hasBeenInitted;
	int _screenW;
	int _screenH;
	int _bufferInterval;
	int _bframe;
};

extern RegisterCppObj<Horde3d> g_register_horde3d_object;

#endif
